﻿#region Imports
using System;
using System.Globalization;
using System.Windows.Data;
using CommonUtilities.Util;
#endregion

namespace EntertainmentManager.Converters
{
    public class NumberPaddingConverter : IValueConverter
    {
        #region IValueConverter Members
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string source = Utilities.ExtractConverterInputs<string>(value, "");
            int paddingLength = Utilities.ExtractConverterInputs<int>(parameter, 0, (i) => { return i < 0; });

            return source.PadLeft(paddingLength, '0');
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Utilities.ExtractConverterInputs<string>(value, "").Trim('0');
        }
        #endregion
    }
}
